//
//  BJMineArticleListTableViewCell.m
//  BowJoy
//
//  Created by  on 2024/5/27.
//

#import "BJMineArticleListTableViewCell.h"

@implementation BJMineArticleListTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (void)setModel:(BJAnchorWallModelData *)model{
    [self.headerIcon sd_setImageWithURL:[NSURL URLWithString:model.avatar] completed:nil];
    self.titleL.text = [self getLenghtStr:model.nickname withCount:20];
    self.contenL.text = [self getLenghtStr:model.content withCount:15];
    NSArray *imageArr = [model.imageArrStr componentsSeparatedByString:@","];


    if (imageArr.count>0){
        self.anchorImage.hidden = NO;
        self.anchorImage.image = [self readImageFromDocumentsWithName:imageArr[0]];
    }else{
        self.anchorImage.hidden = YES;
    }
    
    if (imageArr.count>1){
        self.anchorImage1.hidden = NO;
        self.anchorImage1.image = [self readImageFromDocumentsWithName:imageArr[1]];
    }else{
        self.anchorImage1.hidden = YES;
    }
    
    if (imageArr.count>2){
        self.anchorImage2.hidden = NO;
        self.anchorImage2.image = [self readImageFromDocumentsWithName:imageArr[2]];
    }else{
        self.anchorImage2.hidden = YES;
    }
    
    
    self.followIcon.image = model.isLike ? [UIImage imageNamed:@"icon_love_red"]:[UIImage imageNamed:@"icon_love_gray"];
    self.folloeNumL.text = [NSString stringWithFormat:@"%ld",model.followNum];
}
// 从沙盒中读取图片
- (UIImage *)readImageFromDocumentsWithName:(NSString *)imageName {
    NSString *documentsDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    NSString *filePath = [documentsDirectoryPath stringByAppendingPathComponent:imageName];
    NSData *imageData = [NSData dataWithContentsOfFile:filePath];
    UIImage *image = [UIImage imageWithData:imageData];
    
    return image;
}
- (NSString *)getLenghtStr:(NSString *)str withCount:(NSInteger)count{
    NSString * str1 = str;
    if (str.length>count){
        NSRange range = [str rangeOfComposedCharacterSequenceAtIndex:count];
        NSString *subStr = [str substringToIndex:range.location];
        str1 = [NSString stringWithFormat:@"%@...",subStr];
    }
    
    return str1;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
